package jee.boot.module.bpm.rest;

import jee.boot.common.basic.CrudController;
import jee.boot.common.basic.ServiceException;
import jee.boot.common.basic.result.ResponseMessage;
import jee.boot.common.basic.result.Result;
import jee.boot.entity.bpm.FormDefinition;
import jee.boot.module.bpm.service.FormDefinitionService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 表单定义
 */
@RestController
@RequestMapping("/formDefinition")
public class FormDefinitionRestController extends CrudController<FormDefinitionService, FormDefinition> {

    /**
     * 根据名称查询表单设计
     *
     * @param entity
     * @return
     */
    @PostMapping("/getByName")
    public ResponseMessage<FormDefinition> getByName(@RequestBody FormDefinition entity) {
        FormDefinition data = service.getByName(entity);
        return Result.success(data);
    }

    @PostMapping("/publish")
    public ResponseMessage<FormDefinition> publish(@RequestBody FormDefinition entity) {
        try {
            service.publish(entity);
            return Result.success();
        } catch (ServiceException e) {
            return Result.requestError(e.getMessage());
        }
    }

}
